package com.xhsj.user.hr.process.hrBecomeRegular.service;

import com.xhsj.user.hr.process.dto.hrBecomeRegular.*;
import com.xhsj.user.hr.process.dto.processDefinition.HandleAuditDto;
import com.xhsj.user.hr.process.hrBecomeRegular.entity.TbHrApprovalBecomeRegularApply;
import com.xhsj.user.hr.process.hrBecomeRegular.entity.TbHrApprovalBecomeRegularApplyQuestion;
import com.xhsj.user.hr.process.hrBecomeRegular.mapper.TbHrApprovalBecomeRegularApplyMapper;
import com.xhsj.user.hr.process.hrBecomeRegular.query.*;
import com.xhsj.user.hr.process.hrBecomeRegular.service.TbHrApprovalBecomeRegularApplyService;
import com.xhsj.user.hr.base.BaseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xhsj.user.hr.process.hrLeaveProcess.mapper.TbHrApprovalLeaveApplyMapper;
import com.xhsj.user.hr.process.hrLeaveProcess.query.ApprovalHiTaskQuery;
import com.xhsj.user.hr.process.hrLeaveProcess.query.WorkFlowNodeQuery;
import com.xhsj.user.hr.process.processDefinition.query.ProcessNodeQuery;
import com.xhsj.user.hr.process.processDefinition.service.TbGlobalApprovalHiTaskService;
import com.xhsj.user.hr.process.processDefinition.service.TbGlobalApprovalTaskService;
import com.xhsj.user.hr.process.processDefinition.service.TbGlobalWorkFlowNodeService;
import com.xhsj.user.hr.process.query.ApprovalQuery;
import com.xhsj.user.security.entity.LoginUser;
import com.xhsj.user.hr.system.entity.TbGlobalUser;
import com.xhsj.user.hr.system.mapper.TbGlobalRoleMapper;
import com.xhsj.user.hr.system.service.TbGlobalUserService;
import com.xhsj.user.hr.system.vo.MonthCountVo;
import com.xhsj.user.hr.userInfo.entity.TbGlobalUserDetail;
import com.xhsj.user.hr.userInfo.service.TbGlobalUserDetailService;
import com.xhsj.user.utils.MessageConstant;
import com.xhsj.user.utils.QuestionAndAnswerTreeUtils;
import com.xhsj.user.utils.ScoreQueriesTreeUtils;
import com.xhsj.user.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import lombok.extern.slf4j.Slf4j;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * hr流程_转正申请表 服务实现类
 * </p>
 *
 * @author liuqinghua
 * @since Sep 10, 2020 3:48:00 PM
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
//@CacheConfig(cacheNames = "TbHrApprovalBecomeRegularApply")
public class TbHrApprovalBecomeRegularApplyService extends BaseService<TbHrApprovalBecomeRegularApplyMapper, TbHrApprovalBecomeRegularApply>{
    @Autowired
    private TbHrApprovalBecomeRegularApplyMapper dao;

    // hr流程_转正申请与问题评分中间表 服务实现类
    @Autowired
    private TbHrApprovalBecomeRegularApplyQuestionService tbHrApprovalBecomeRegularApplyQuestionService;

    // 流程-任务审核表 服务实现类
    @Autowired
    private TbGlobalApprovalTaskService tbGlobalApprovalTaskService;

    // 用户信息表 服务实现类
    @Autowired
    private TbGlobalUserService tbGlobalUserService;

    // 角色信息表 Mapper 接口
    @Autowired
    private TbGlobalRoleMapper tbGlobalRoleMapper;

    // 流程-历史表 服务实现类
    @Autowired
    private TbGlobalApprovalHiTaskService tbGlobalApprovalHiTaskService;

    // 流程设计-流程节点 服务实现类
    @Autowired
    private TbGlobalWorkFlowNodeService tbGlobalWorkFlowNodeService;

    // 用户信息表 服务实现类
    @Autowired
    private TbGlobalUserDetailService tbGlobalUserDetailService;

    @Autowired
    private TbHrApprovalLeaveApplyMapper tbHrApprovalLeaveApplyMapper;

	/**
	 * 保存
	 * @author liuqinghua
	 * @date Sep 10, 2020 3:48:00 PM
	 */
    @Override
    //@CacheEvict(cacheNames="TbHrApprovalBecomeRegularApply", allEntries=true)
    public boolean save(TbHrApprovalBecomeRegularApply entity) {
        return super.save(entity);
    }

	/**
	 * 通过id获取数据
	 * @author liuqinghua
	 * @date Sep 10, 2020 3:48:00 PM
	 */
    @Override
    //@Cacheable(key = "#id",sync = true)
    public TbHrApprovalBecomeRegularApply getById(Serializable id) {
        return super.getById(id);
    }

	/**
	 * 通过id删除数据
	 * @author liuqinghua
	 * @date Sep 10, 2020 3:48:00 PM
	 */
    @Override
    //@CacheEvict(cacheNames="TbHrApprovalBecomeRegularApply", allEntries=true)
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

	/**
	 * 批量删除数据
	 * @author liuqinghua
	 * @date Sep 10, 2020 3:48:00 PM
	 */
    //@CacheEvict(cacheNames="SysDict", allEntries=true)
    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        return super.removeByIds(idList);
    }

	/**
	 * 分页查询数据
	 * @author liuqinghua
	 * @date Sep 10, 2020 3:48:00 PM
	 */
    //@Cacheable(key = "#data",sync = true)
    public IPage<TbHrApprovalBecomeRegularApply> selectPage(Map<String,Object> data) {
        int currentPage=1;
        if (!Objects.isNull(data.get("page"))) {
            currentPage=(Integer) data.get("page");
        }
        int pageSize=20;
        if (!Objects.isNull(data.get("size"))) {
            pageSize=(Integer) data.get("size");
        }

        TbHrApprovalBecomeRegularApply entity = JSON.parseObject(JSON.toJSONString(data), TbHrApprovalBecomeRegularApply.class);
        Page<TbHrApprovalBecomeRegularApply> page = new Page(currentPage,pageSize);
        QueryWrapper<TbHrApprovalBecomeRegularApply> wrapper = new QueryWrapper(entity);
        return super.selectPage(page, wrapper);
    }

	/**
	 * 查询所有数据
	 * @author liuqinghua
	 * @date Sep 10, 2020 3:48:00 PM
	 */
    @Override
    //@Cacheable(value = "TbHrApprovalBecomeRegularApply",sync = true)
    public List<TbHrApprovalBecomeRegularApply> selectAll() {
        return super.selectAll();
    }


    /**
     * 获取用户要转正申请得数据
     * @author liuqinghua
     * @date Sep 10, 2020 3:48:00 PM
     */
    public BecomeRegularDataQuery getBecomeRegularData(Long userId) {
        return dao.getBecomeRegularData(userId);
    }

    /**
     * 转正申请开始流程
     * @author liuqinghua
     * @date Sep 10, 2020 3:48:00 PM
     */
    public ApprovalQuery startBecomeRegularApply(StartBecomeRegularApplyDto data) throws Exception {
        // 保存申请表
        TbHrApprovalBecomeRegularApply apply = data.getApply();
        if (!super.save(apply)) {
            throw new Exception("保存转正申请表异常");
        }
        // 保存自评分数
        List<TbHrApprovalBecomeRegularApplyQuestion> applyQuestionList = data.getApplyQuestionList();
        if (applyQuestionList.size() > 0) {
            for (TbHrApprovalBecomeRegularApplyQuestion applyQuestion: applyQuestionList ) {
                applyQuestion.setBecomeRegularApplyId(apply.getId());
                if (!tbHrApprovalBecomeRegularApplyQuestionService.save(applyQuestion)) {
                    throw new Exception("保存自评分数异常");
                }
            }
        }
        // 执行流程
        ApprovalQuery approvalQuery = this.startBecomeRegularApplyRun(apply);
        return approvalQuery;
    }

    /**
     * 执行开始转正流程启动
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public ApprovalQuery startBecomeRegularApplyRun( TbHrApprovalBecomeRegularApply apply) throws Exception {
        HandleAuditDto handleAuditDto = new HandleAuditDto();
        handleAuditDto.setDataId(apply.getId());
        handleAuditDto.setProposerId(apply.getCreateBy());
        handleAuditDto.setCreateBy(apply.getCreateBy());
        handleAuditDto.setApplyType(6);
        // 执行流程
        ProcessNodeQuery processNodeQuery = tbGlobalApprovalTaskService.startHandleAudit(handleAuditDto,apply.getDepartmentId());
        // 修改转正申请表节点名称和节点id
        ApprovalQuery approvalQuery = this.updateHrApprovalEntryApply(handleAuditDto, processNodeQuery);
        return approvalQuery;
    }

    public ApprovalQuery updateHrApprovalEntryApply(HandleAuditDto data,ProcessNodeQuery processNodeQuery) throws Exception {
        TbHrApprovalBecomeRegularApply tbHrApprovalBecomeRegularApply = new TbHrApprovalBecomeRegularApply();
        tbHrApprovalBecomeRegularApply.setId(data.getDataId());
        tbHrApprovalBecomeRegularApply.setNodeName(processNodeQuery.getNodeName());
        tbHrApprovalBecomeRegularApply.setNodeId(processNodeQuery.getNodeId());
        tbHrApprovalBecomeRegularApply.setBusinessId(data.getBusinessId());
        tbHrApprovalBecomeRegularApply.setDelFlag(processNodeQuery.getDelFlag());
        if (!this.save(tbHrApprovalBecomeRegularApply)) {
            throw new Exception("修改转正申请节点名称信息异常");
        }
        String fullName = tbHrApprovalLeaveApplyMapper.getFullNameByDataId(data.getDataId(),"tb_hr_approval_become_regular_apply");

        // 消息参数
        return setApprovalQuery(data.getDataId(),4, MessageConstant.MSG_2,processNodeQuery,fullName);
    }

    public ApprovalQuery setApprovalQuery(Long dataId,Integer projectId,String title,ProcessNodeQuery processNodeQuery,String fullName) throws Exception {
        ApprovalQuery approvalQuery = new ApprovalQuery();
        approvalQuery.setDataId(dataId);
        approvalQuery.setProjectId(projectId);
        approvalQuery.setTitle(title);
        approvalQuery.setRoleIds(processNodeQuery.getRoleIds());
        approvalQuery.setUserId(processNodeQuery.getUserId());
        approvalQuery.setCurrentUserId(processNodeQuery.getCurrentUserId());
        approvalQuery.setCreateName(fullName);
        return approvalQuery;
    }
    /**
     * 转正流程审批
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public ApprovalQuery approvalBecomeRegularApply(BecomeRegularHandleAuditDto data) throws Exception {
        // 若流程是申请创建得下一个节点需要评分 和 转正类型  3延期转正   延期转正 作废本申请，设置试用期延长
        ApprovalQuery approvalQuery;
        HandleAuditDto handleAuditDto = data.getHandleAuditDto();
        BecomeRegularApplyDto apply = data.getApply();
        if (handleAuditDto.getNodeId() == 2 ) {
            // 保存评分和综合意见和意见类型
             TbHrApprovalBecomeRegularApply tbHrApprovalBecomeRegularApply = new TbHrApprovalBecomeRegularApply();
              tbHrApprovalBecomeRegularApply.setId(handleAuditDto.getDataId());
              tbHrApprovalBecomeRegularApply.setBecomeRegularType(apply.getBecomeRegularType());
              tbHrApprovalBecomeRegularApply.setBecomeRegularTypeOpinion(apply.getBecomeRegularTypeOpinion());
              tbHrApprovalBecomeRegularApply.setComprehensiveOpinion(apply.getComprehensiveOpinion());
              tbHrApprovalBecomeRegularApply.setLeaderScore(apply.getLeaderScore());
            if (apply.getComprehensiveOpinion() != null) {
                handleAuditDto.setOpinionText(apply.getComprehensiveOpinion());
            }
            if (!super.save(tbHrApprovalBecomeRegularApply)) {
                throw new Exception("保存评分和综合意见和意见类型异常");
            }
        }

        // 保存评分
        if (handleAuditDto.getNodeId() == 2 || handleAuditDto.getNodeId() == 1){
            List<TbHrApprovalBecomeRegularApplyQuestion> applyQuestionList = data.getApplyQuestionList();
            if (applyQuestionList.size() > 0) {
                for (TbHrApprovalBecomeRegularApplyQuestion applyQuestion : applyQuestionList) {
                    applyQuestion.setBecomeRegularApplyId(handleAuditDto.getDataId());
                    if (!tbHrApprovalBecomeRegularApplyQuestionService.save(applyQuestion)) {
                        throw new Exception("保存自评分数异常");
                    }
                }
            }

        }
        //  延期转正 作废本申请，设置试用期延长
        if (handleAuditDto.getNodeId() == 2 && apply.getBecomeRegularType() == 2 && handleAuditDto.getStatus() == 1 ) {
                this.updatePositiveDate(handleAuditDto,apply);
                handleAuditDto.setStatus(3);
                return this.approvalBecomeRegularToVoidApply(handleAuditDto);
        }
            // 执行流程
            ProcessNodeQuery processNodeVo = tbGlobalApprovalTaskService.handleAudit(handleAuditDto);
            // 修改产品申请表节点名称和节点id
              approvalQuery = updateHrApprovalEntryApply(handleAuditDto, processNodeVo);

            // 当前时间
            Date day = new Date();
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            String format = df.format(day);
            long time = df.parse(format).getTime();
            // 修改用户正式标识
            if ("完结".equals(processNodeVo.getNodeName()) && (apply.getBecomeRegularType()==0 || apply.getBecomeRegularType() == 2)){
                this.updatePositiveDate(handleAuditDto,apply);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Date date = simpleDateFormat.parse(apply.getBecomeRegularTypeOpinion());
                TbHrApprovalBecomeRegularApply tbHrApprovalBecomeRegularApply = new TbHrApprovalBecomeRegularApply();
                tbHrApprovalBecomeRegularApply.setPositiveDate(date);
                QueryWrapper<TbHrApprovalBecomeRegularApply> queryWrapper2 = new QueryWrapper();
                queryWrapper2.eq("id",handleAuditDto.getDataId());
                if (!super.update(tbHrApprovalBecomeRegularApply, queryWrapper2)) {
                    throw new Exception("设置试用期延长异常");
                }
            }
            if ("完结".equals(processNodeVo.getNodeName()) && apply.getBecomeRegularType() != 2 && apply.getPositiveDate().getTime() <= time) {
                TbGlobalUser tbGlobalUser = new TbGlobalUser();
                tbGlobalUser.setUserId(apply.getUserId());
                tbGlobalUser.setJobStatus(1);
                if (!tbGlobalUserService.updateById(tbGlobalUser)) {
                    throw new Exception("修改用户正式标识异常");
                }
            }
        return approvalQuery;
    }

    // 设置试用期延长
    public void updatePositiveDate( HandleAuditDto handleAuditDto,BecomeRegularApplyDto apply) throws Exception {
        Long proposerId = apply.getUserId();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = simpleDateFormat.parse(apply.getBecomeRegularTypeOpinion());
        apply.setPositiveDate(date);
        TbGlobalUserDetail tbGlobalUserDetail = new TbGlobalUserDetail();
        tbGlobalUserDetail.setPositiveDate(date);
        QueryWrapper<TbGlobalUserDetail> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",proposerId);
        if (!tbGlobalUserDetailService.update(tbGlobalUserDetail, queryWrapper)) {
            throw new Exception("设置试用期延长异常");
        }

    }

    /**
     * 转正定时器 定期生效
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public void approvalBecomeRegularEffective() throws Exception {
        Date day = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String format = df.format(day);
        // 获取今天将生效的调岗
        QueryWrapper<TbHrApprovalBecomeRegularApply> queryWrapper = new QueryWrapper();
        queryWrapper.eq("positive_date",format);
        queryWrapper.eq("node_name","完结");
        queryWrapper.ne("become_regular_type",3);
        List<TbHrApprovalBecomeRegularApply> tbHrApprovalBecomeRegularApplyJobs = dao.selectList(queryWrapper);
        for (TbHrApprovalBecomeRegularApply tbHrApprovalBecomeRegularApplyJob : tbHrApprovalBecomeRegularApplyJobs) {
            TbGlobalUser tbGlobalUser = new TbGlobalUser();
            tbGlobalUser.setUserId(tbHrApprovalBecomeRegularApplyJob.getUserId());
            tbGlobalUser.setJobStatus(1);
            if (!tbGlobalUserService.updateById(tbGlobalUser)) {
                throw new Exception("修改用户正式标识异常");
            }
        }

    }

    /**
     * 我的转正申请列表
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public IPage<MyBecomeRegularApplyListQuery> myBecomeRegularApplyList(MyBecomeRegularApplyListDto data) {
        Page<MyBecomeRegularApplyListQuery> page = new Page(data.getPage(),data.getSize());
        LoginUser loginAppUser = UserUtils.getLoginAppUser();
        Long userId = loginAppUser.getUserId();
        return dao.myBecomeRegularApplyList(page,data,userId);
    }

    /**
     * 待审核转正申请列表
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public IPage<RunBecomeRegularApplyListQuery> runBecomeRegularyApplyList(RunBecomeRegularApplyListDto data) {
        Page<RunBecomeRegularApplyListQuery> page = new Page(data.getPage(),data.getSize());
        LoginUser loginAppUser = UserUtils.getLoginAppUser();
        Long userId = loginAppUser.getUserId();
        // 获取用户角色id
        List<Long> roleList = tbGlobalRoleMapper.getRoleListByUserId(userId);
        return dao.runBecomeRegularyApplyList(page,data,userId,roleList);
    }

    /**
     * 已审核转正申请列表
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public IPage<CompletedBecomeRegularApplyQuery> completedBecomeRegularApplyList(RunBecomeRegularApplyListDto data) {
        Page<CompletedBecomeRegularApplyQuery> page = new Page<>(data.getPage(),data.getSize());
        LoginUser loginAppUser = UserUtils.getLoginAppUser();
        Long userId = loginAppUser.getUserId();
        return dao.completedBecomeRegularApplyList(page,userId,data);
    }

    /**
     * 转正申请详细信息
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public MyBecomeRegularDetailedListQuery myBecomeRegularApplyDetailedList(Long dataId) {
        MyBecomeRegularDetailedListQuery myBecomeRegularDetailedListQuery = new MyBecomeRegularDetailedListQuery();
        // 基本信息
        MyBecomeRegularBaseDetailedListQuery myBecomeRegularBaseDetailedList = dao.getMyBecomeRegularBaseDetailedList(dataId);
        if (myBecomeRegularBaseDetailedList != null) {
            myBecomeRegularDetailedListQuery.setApplyList(myBecomeRegularBaseDetailedList);
            Long businessId = myBecomeRegularBaseDetailedList.getBusinessId();
            // 审批意见
        List<ApprovalHiTaskQuery> approvalHiTaskList = tbGlobalApprovalHiTaskService.getApprovalHiTaskList(dataId, businessId);
        myBecomeRegularDetailedListQuery.setCommentList(approvalHiTaskList);

        // 流程节点
        List<WorkFlowNodeQuery> workFlowNodeQueries = tbGlobalWorkFlowNodeService.nodeList(businessId);
        myBecomeRegularDetailedListQuery.setNodeList(workFlowNodeQueries);
        }
        return myBecomeRegularDetailedListQuery;
    }

    /**
     * 全部转正申请列表
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public IPage<MyBecomeRegularApplyListQuery> allBecomeRegularApplyList(MyBecomeRegularApplyListDto data) {
        Page<MyBecomeRegularApplyListQuery> page = new Page(data.getPage(),data.getSize());
        return dao.allBecomeRegularApplyList(page,data);
    }

    /**
     * 我的转正申请详细信息之评审分数
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public List<MyBecomeRegularApplyDetailedListScoreQuery> myBecomeRegularApplyDetailedListScore(Long dataId) {
        List<MyBecomeRegularApplyDetailedListScoreQuery> myBecomeRegularApplyDetailedListScoreQueries = dao.myBecomeRegularApplyDetailedListScore(dataId);
        Long aLong = new Long(0);
        return ScoreQueriesTreeUtils.getChildPerms(myBecomeRegularApplyDetailedListScoreQueries,aLong);
    }

    /**
     * 查询每月转正人数
     * @author 苏小林
     * @date 2020/9/14 16:00
     * @param: date
     * @return: int[]
     */
    public int[] getCountByDate(String date) {
        Calendar calendar = Calendar.getInstance();
        //获得当前年
        int year=calendar.get(Calendar.YEAR);

        //获得当前时bai间的月份，月份从0开始所以结果要加1
        int month=calendar.get(Calendar.MONTH)+1;
        //定义数组
        int[] countVIP = new int[month];

        if (StringUtils.isBlank(date)) {
            date = year +"";
        } else {
            if (!date.equals(year+"")) {
                countVIP = new int[12];
            }
        }

        List<MonthCountVo> list = dao.getCountByDate(date);
        // 判断当月时间
        String year1 = String.valueOf(LocalDate.now().getYear());
        MonthCountVo cunrrentCountByDate = null;
        if(year1.equals(date))
            cunrrentCountByDate = dao.getCunrrentCountByDate();
        if (list.size() >0 && list != null) {
            for (int i = 0; i < list.size(); i++) {
                MonthCountVo monthCountVo = list.get(i);
                if (monthCountVo != null) {
                    if(cunrrentCountByDate != null && cunrrentCountByDate.getMonth() == monthCountVo.getMonth()){
                        monthCountVo.setCount(cunrrentCountByDate.getCount());
                    }
                    //填充月份对应的数据
                    countVIP[monthCountVo.getMonth()-1] = monthCountVo.getCount();
                }

            }
        }
        return countVIP;
    }

    /**
     * 转正流程重新提交
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public ApprovalQuery returnBecomeRegularApply(BecomeRegularHandleAuditDto data) throws Exception {
        HandleAuditDto handleAudit = data.getHandleAuditDto();
        // 修改申请数据
        BecomeRegularApplyDto apply = data.getApply();
        TbHrApprovalBecomeRegularApply tbHrApprovalBecomeRegularApply = new TbHrApprovalBecomeRegularApply();
        tbHrApprovalBecomeRegularApply.setSelfAssessment(apply.getSelfAssessment());
        tbHrApprovalBecomeRegularApply.setSelfLack(apply.getSelfLack());
        tbHrApprovalBecomeRegularApply.setSelfScore(apply.getSelfScore());
        tbHrApprovalBecomeRegularApply.setId(handleAudit.getDataId());
        if (!super.updateById(tbHrApprovalBecomeRegularApply)) {
            throw new Exception("修改申请数据异常");
        }
        // 执行流程
        handleAudit.setStatus(0);
       return this.approvalBecomeRegularApply(data);
    }

    /**
     * 转正流程作废
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public ApprovalQuery approvalBecomeRegularToVoidApply(HandleAuditDto data) throws Exception {
        LoginUser loginAppUser = UserUtils.getLoginAppUser();
        Long userId = loginAppUser.getUserId();
        // 修改用户转正标志
        TbGlobalUser tbGlobalUser = new TbGlobalUser();
        tbGlobalUser.setJobStatus(0);
        tbGlobalUser.setUserId(userId);
       if(!tbGlobalUserService.updateById(tbGlobalUser)){
           throw new Exception("修改用户转正标志数据异常");
       }
        // 执行流程
        data.setNodeId(-11L);
        ProcessNodeQuery processNodeVo = tbGlobalApprovalTaskService.handleAudit(data);

        // 修改产品申请表节点名称和节点id
         return updateHrApprovalEntryApply(data,processNodeVo);
    }
}
